<template>
  <el-dialog title="人员选择" :visible.sync="modal" width="600px" :before-close="handleClose" append-to-body>
    <Dep @getDept="getDept" :selectedPersons="selectedPersons" :fatherStatus="modal" @selectChange="selectChange" />
    <span slot="footer" class="dialog-footer">
      <!--<el-button @click="resetForm('dynamicValidateForm')">重 置</el-button>-->
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitForm('dynamicValidateForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import Dep from "./deptPerson.vue";
  import {
    deepClone
  } from "../../lib/utils";
  export default {
    components: {
      Dep
    },
    props: {
      selected: {
        type: Array
      },
      isOpen: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        modal: this.isOpen,
        selectedPersons: [],
        currentId: null
      }
    },
    methods: {
      /**
       * 表单提交
       */
      submitForm(formName) {
          this.$emit('selectChange', this.selectedPersons);
          console.log(' this.selectedPersons===========================', this.selectedPersons)
          this.handleClose();
      },
      /**
       * 取消操作
       */
      cancel() {
        this.handleClose();
      },
      /**
       * 获取当前选择的部门id
       */
      getDept(val) {
        this.currentId = val;
      },
      /**
       * 获取当前选择的部门id
       */
      selectChange(val) {
        this.selectedPersons = deepClone(val);
      },
      /**
       * 关闭模态框
       */
      handleClose(val) {
        this.modal = false;
        this.$emit('modalClose', this.modal);
      },
      /**
       * 清空表单
       */
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
    },
    watch: {
      /**
       * 监听模态框开启状态
       */
      isOpen(newval) {
        if (newval) {
          this.modal = newval;
          console.log('this.selected======================',this.selected)
          this.selectedPersons = deepClone(this.selected);
          //this.formatSelectedData();
        }
      }
    }
  }

</script>

<style scoped>


</style>

